﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XchangeStreamer.Subscriber.SDK;
using XchangeStreamer.Types;
using XchangeStreamer.Types.Google;

namespace GoogleSubscriber
{
    class Program
    {
        private static Connector connector;
        static void Main(string[] args)
        {
            Console.Write("Please enter streamer info (IP/Port):");
            string[] streamerInfo = Console.ReadLine().Split('/');

            Console.Write("Please enter cache server info (IP/Port):");
            string[] cacheServerInfo = Console.ReadLine().Split('/');

            string streamerIP = streamerInfo.Length < 2 ? "localhost" : streamerInfo[0];
            string streamerPort = streamerInfo.Length < 2 ? null : streamerInfo[1];
            string cacheServerIP = cacheServerInfo.Length < 2 ? "localhost" : cacheServerInfo[0];
            string cacheServerPort = cacheServerInfo.Length < 2 ? null : cacheServerInfo[1];

            connector = Connector.Connection;
            connector.Connect(streamerIP, streamerPort, cacheServerIP, cacheServerPort);

            connector.Subscribe<RealTime, List<RealTime>>(1, GoogleTickerLogic);

            Console.ReadKey();
            connector.Unsubscribe(1);
            connector.Disconnect();
        }

        private static void GoogleTickerLogic(List<RealTime> tickers, int messageId, TimeSpan time)
        {
            foreach (var ticker in tickers)
            {
                Console.WriteLine("Company: {0} | TradeTimeStamp: {1}", ticker.Company, ticker.TradeTimeStamp);
            }
        }
    }
}